package 动态规划专项训练.动态规划训练1;

/**674.最长连续递增序列
 * 求最值型动态规划
 * @author zx
 * @create 2022-03-30 23:25
 */
public class Num674 {
    int result = 0;
    public int findLengthOfLCIS(int[] nums) {
        int n = nums.length;
        if(n == 0){
            return 0;
        }
        calc(nums,n);
        return result;
    }
    private void calc(int[] nums,int n){
        int[] f = new int[n];
        for(int i = 0;i < n;i++){
            f[i] = 1;
            if(i > 0 && nums[i - 1] < nums[i]){
                f[i] = f[i - 1] + 1;
            }
            if(f[i] > result){
                result = f[i];
            }
        }
    }
    public int findLengthOfLCIS2(int[] nums) {
        //滚动数组优化空间复杂度为O(1)
        int n = nums.length;
        if(n == 0){
            return 0;
        }
        calc(nums,n);
        return result;
    }
    private void calc2(int[] nums,int n){
        int[] f = new int[2];
        int olds = 0;
        int news = 0;
        for(int i = 0;i < n;i++){
            olds = news;
            news = 1 - news;
            f[news] = 1;
            if(i > 0 && nums[i - 1] < nums[i]){
                f[news] = f[olds] + 1;
            }
            if(f[news] > result){
                result = f[news];
            }
        }
    }
}
